package com.atguigu.springcloud.service;

import com.atguigu.springcloud.exception.PaymentBusinessException;
import com.atguigu.springcloud.exception.PaymentBusinessExceptionEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @Author lizhilong
 * @create 2020/5/3 14:44
 * @desc
 */
@Service
@Slf4j
public class PaymentService {

    public String payment_ok(int id){
        log.info("*******************");
        return "线程池："+Thread.currentThread().getName() +"    "+ "payment_ok:"+id;
    }

    public String time_out(int id ){
        int number = 2000 ;
        try {
            TimeUnit.MILLISECONDS.sleep(number);
        }catch (Exception e ){
            e.printStackTrace();
        }
        log.info("####################");
        return "线程池："+Thread.currentThread().getName() +"    "+ "time_out:"+id;
    }

    public String breakerTest(int i){
        if(i<0){
            throw new PaymentBusinessException(PaymentBusinessExceptionEnum.RECORD_NOT_FOUND);
        }else {
            return "请求成功，O(∩_∩)O哈哈~ "+ UUID.randomUUID().toString();
        }
    }
}
